﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Tycho.Runtime;

namespace Tycho.PerformanceTests {
    class Program {
        static void Main (string [] args) {
            var runtime = TopLevel.RuntimeAssemblyModule;
            FindOperationsToBenchMark ();
            Console.WriteLine ("Press any key");
            Console.ReadKey (true);
        }

        static void FindOperationsToBenchMark() {
            Assembly assembly = typeof (Program).Assembly;

            foreach (var type in assembly.GetTypes ()) {
                foreach (var method in type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)) {
                    if (method.GetCustomAttributes (typeof (BenchMarkAttribute), false).Length > 0) {
                        BenchMarkOperation (method);
                    }
                }
            }
        }

        private static void BenchMarkOperation (MethodInfo method) {
            Console.Write ("{0}.{1}: ", method.DeclaringType.FullName, method.Name);
            DateTime start = DateTime.Now;
            method.Invoke (null, null);
            Console.WriteLine ("{0:0.00} milliseconds", (DateTime.Now - start).TotalMilliseconds);
        }
    }
}
